# Contributor: Raed Rizqie <raed.rizqie@gmail.com>

_realname=spyder
pkgbase=mingw-w64-python-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-python-${_realname}
pkgver=6.0.7
pkgrel=1
pkgdesc='The Scientific Python Development Environment (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64')
url='https://www.spyder-ide.org/'
msys2_repository_url='https://github.com/spyder-ide/spyder'
msys2_references=(
  'archlinux: spyder'
  'purl: pkg:pypi/spyder'
)
license=('spdx:MIT')
depends=(
    ${MINGW_PACKAGE_PREFIX}-python
    ${MINGW_PACKAGE_PREFIX}-python-aiohttp
    ${MINGW_PACKAGE_PREFIX}-python-atomicwrites
    ${MINGW_PACKAGE_PREFIX}-python-asyncssh
    ${MINGW_PACKAGE_PREFIX}-python-bcrypt
    ${MINGW_PACKAGE_PREFIX}-python-chardet
    ${MINGW_PACKAGE_PREFIX}-python-cloudpickle
    ${MINGW_PACKAGE_PREFIX}-python-cookiecutter
    ${MINGW_PACKAGE_PREFIX}-python-diff-match-patch
    ${MINGW_PACKAGE_PREFIX}-python-importlib-metadata
    ${MINGW_PACKAGE_PREFIX}-python-intervaltree
    ${MINGW_PACKAGE_PREFIX}-python-ipython
    ${MINGW_PACKAGE_PREFIX}-python-jedi
    ${MINGW_PACKAGE_PREFIX}-python-jellyfish
    ${MINGW_PACKAGE_PREFIX}-python-jsonschema
    ${MINGW_PACKAGE_PREFIX}-python-keyring
    ${MINGW_PACKAGE_PREFIX}-python-jupyter-nbconvert
    ${MINGW_PACKAGE_PREFIX}-python-numpydoc
    ${MINGW_PACKAGE_PREFIX}-python-parso
    ${MINGW_PACKAGE_PREFIX}-python-pexpect
    ${MINGW_PACKAGE_PREFIX}-python-pickleshare
    ${MINGW_PACKAGE_PREFIX}-python-psutil
    ${MINGW_PACKAGE_PREFIX}-python-pygments
    ${MINGW_PACKAGE_PREFIX}-python-pylint
    ${MINGW_PACKAGE_PREFIX}-python-pylint-venv
    ${MINGW_PACKAGE_PREFIX}-python-lsp-black
    ${MINGW_PACKAGE_PREFIX}-python-pyls-spyder
    ${MINGW_PACKAGE_PREFIX}-python-pyqt5
    ${MINGW_PACKAGE_PREFIX}-python-lsp-server
    ${MINGW_PACKAGE_PREFIX}-python-pygithub
    ${MINGW_PACKAGE_PREFIX}-python-pyzmq
    ${MINGW_PACKAGE_PREFIX}-python-pyuca
    ${MINGW_PACKAGE_PREFIX}-python-qdarkstyle
    ${MINGW_PACKAGE_PREFIX}-python-qstylizer
    ${MINGW_PACKAGE_PREFIX}-python-qtawesome
    ${MINGW_PACKAGE_PREFIX}-python-qtconsole
    ${MINGW_PACKAGE_PREFIX}-python-qtpy
    ${MINGW_PACKAGE_PREFIX}-python-rtree
    ${MINGW_PACKAGE_PREFIX}-python-setuptools
    ${MINGW_PACKAGE_PREFIX}-python-sphinx
    ${MINGW_PACKAGE_PREFIX}-python-spyder-kernels
    ${MINGW_PACKAGE_PREFIX}-python-superqt
    ${MINGW_PACKAGE_PREFIX}-python-textdistance
    ${MINGW_PACKAGE_PREFIX}-python-three-merge
    ${MINGW_PACKAGE_PREFIX}-python-watchdog
    ${MINGW_PACKAGE_PREFIX}-python-yarl
    ${MINGW_PACKAGE_PREFIX}-qtwebkit
)
optdepends=(
    ${MINGW_PACKAGE_PREFIX}-cython
    ${MINGW_PACKAGE_PREFIX}-python-matplotlib
    ${MINGW_PACKAGE_PREFIX}-python-numpy
    ${MINGW_PACKAGE_PREFIX}-python-pandas
    ${MINGW_PACKAGE_PREFIX}-python-scipy
)
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
options=(!strip)
source=(https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz
        spyder-requirements-fix.patch)
sha256sums=('431a0c46a34a6490664763d47b1e48f3be03e75e7e43c37adb239022e8b062cf'
            'a5ea57d8458b2d069abd8c72f763b63a25aed1ad62e27a94a0c17d253a0c5fbf')

prepare() {
  cd ${_realname}-${pkgver}

  patch -p1 -i "${srcdir}"/spyder-requirements-fix.patch
}

build() {
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"
  python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd "python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 LICENSE.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
